using System;
using System.Collections.Generic;
using System.Text;

using System.Diagnostics;

namespace EC.TSVNVsPackage.TSvn
{
    internal class TSvnProcess
    {
        ProcessStartInfo psi;

        public TSvnProcess() {
            psi = new ProcessStartInfo("TortoiseProc.exe");
        }

        public void Update(string path) {
            CheckPath(path);
            Run(string.Format("/command:update /path:\"{0}\" /notempfile", path));
        }

        internal void CheckForModifications(string path) {
            CheckPath(path);
            Run(string.Format("/command:repostatus /path:\"{0}\"", path));
        }

        internal void Log(string path) {
            CheckPath(path);
            Run(string.Format("/command:log /path:\"{0}\"", path));
        }

        internal void Commit(string path) {
            CheckPath(path);
            Run(string.Format("/command:commit /path:\"{0}\" /notempfile", path));
        }

        internal void Blame(string path) {
            CheckPath(path);
            Run(string.Format("/command:blame /path:\"{0}\" /notempfile", path));
        }

        internal void Diff(string path) {
            CheckPath(path);
            Run(string.Format("/command:diff /path:\"{0}\" /notempfile", path));
        }

        private void CheckPath(string path) {
            if (path == null)
                throw new ArgumentNullException("path");
            if (path.Length == 0)
                throw new ArgumentException("Can't be empty.", "path");
        }

        private void Run(string args) {
            psi.Arguments = args;
            Process proc = new Process();
            proc.StartInfo = psi;
            proc.Start();
        }
    }
}
